package main

import "fmt"

func main() {
	str := "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
	fmt.Println(len(str))
	fmt.Println(compress(str))
}

/**
 * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
 * 使用题目中描述的方法，将 raw_str 压缩后返回
 * @param raw_str string字符串 未压缩的原始字符串
 * @return string字符串
 */
func compress(raw_str string) string {
	cs := make([]byte, 4, 56)
	for i := 0; i < 26; i++ {
		cs = append(cs, 'a'+byte(i))
	}
	for i := 0; i < 26; i++ {
		cs = append(cs, 'A'+byte(i))
	}

	// write code here
	bs := []byte(raw_str)
	res := make([]byte, 0)
	i, n := 0, 0
	for j := 1; j <= len(bs); j++ {
		if j == len(bs) || bs[j] != bs[i] {
			n = j - i
			if n > 55 {
				for n > 55 {
					if n < 59 {
						res = append(res, []byte{'0', cs[n-4], bs[i], '0', 'a', bs[i]}...)
						n = 0
					} else {
						res = append(res, []byte{'0', 'Z', bs[i]}...)
						n -= 55
					}
				}
				if n > 0 {
					res = append(res, []byte{'0', cs[n], bs[i]}...)
				}
			} else if n >= 4 && n < 55 {
				res = append(res, []byte{'0', cs[n], bs[i]}...)
			} else {
				res = append(res, bs[i:j]...)
			}
			i = j
		}
	}

	return string(res)
}
